package com.charles.video.common.core.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * MD5加密工具
 * 
 * @author Charles-H
 */
public class Md5Utils {

    // 密钥
    private static final String salt = "CHARLESVIDEO-KEY";

    public static String md5(String str) {
        return DigestUtils.md5Hex(str);
    }

    // 一次加密
    public static String inputPwdToFormPwd(String inputPwd) {
        // 混淆
        String str = " " + salt.charAt(4) + salt.charAt(1) + inputPwd + salt.charAt(9);
        return md5(str);
    }

    // 二次加密
    public static String formPwdToDbPwd(String formPwd,String salt) {
        String str = salt.charAt(7) + salt.charAt(4) + formPwd + salt.charAt(10);
        return md5(str);
    }

    // 两次加密
    public static String inputPwdToDbPwd(String inputPwd){
        String formPwd = inputPwdToFormPwd(inputPwd);
        String dbPass = formPwdToDbPwd(formPwd, salt);
        return dbPass;
    }
    
}
